/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.s2aei.busisnes;

import com.s2aei.model.Aluno;
import com.s2aei.model.Papeis;
import com.s2aei.model.Status;
import com.s2aei.model.Usuario;
import com.s2aei.model.dao.AlunoDao;
import com.s2aei.model.dao.UsuarioDao;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Quirgo
 */
public class AlunoBO {
    
  private Aluno aluno;
  private Usuario user;
  private AlunoDao aDao = new AlunoDao();
  private UsuarioDao uDao = new UsuarioDao();
    
public void criarAluno (Usuario u, Aluno a){
    aluno = a;
    user = u;
int id = (int)(1+(Math.random()*1000));
        aluno.setAlunoId(id);
        user.setUserId(id);
        user.setDataCadastro(new Date());
        user.setDataModificado(new Date());
        user.setStatus(new Status("Ativo"));
        user.setPapel(new Papeis("Aluno"));
        try {
            uDao.create(user);
            aDao.create(aluno);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
}

public void alteraAluno(Usuario u, Aluno a){
    aluno = a;
    user = u;
    try {
            uDao.edit(user);
            aDao.edit(aluno);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
}
public void removeAluno(Usuario u, Aluno a){
    aluno = a;
    user = u;
    try {
            aDao.destroy(aluno.getAlunoId());
            uDao.destroy(aluno.getAlunoId());
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
}
public List listaAlunos(){
    return aDao.findAlunoEntities();
}
}


